import {useMorghulisCookies} from "./cookies";
import {nanoid} from "nanoid";

export const SYSTEM_KEY = {
    CLIENT: 'client', USER: 'uid', AUTH: 'auth',
}
const {load, get, remove, set} = useMorghulisCookies()

export function useMorghulisAuthorize() {
    let $client = nanoid().replace(/-/g, '_')
    $client = load(SYSTEM_KEY.CLIENT, $client)
    const user = () => get(SYSTEM_KEY.USER)
    const check = (uid?: any) => user() === uid
    const login = (uid: any) => set(SYSTEM_KEY.USER, uid)
    const logout = () => remove(SYSTEM_KEY.USER)
    const bearer = () => user() ? `Bearer ${123}` : null
    return {$client, user, check, login, logout, bearer}
}
